<template>
  <el-container>
    <el-header>
      <img src="../assets/images/logo.png" alt="" />
      <el-menu
        active-text-color="rgb(95, 153, 203)"
        mode="horizontal"
        text-color="#fff"
        background-color="rgb(35, 38, 46)"
      >
        <el-submenu index="2">
          <template slot="title"
            ><img class="imgs" v-if="user.user_pic" :src="user.user_pic" alt="" /><img
              class="imgs"
              src="../assets/logo.png"
              alt=""
              v-else
            />个人中心</template
          >
          <el-menu-item index="2-1"><i class="el-icon-edit"></i>基本资料</el-menu-item>
          <el-menu-item index="2-2"><i class="el-icon-edit"></i>修改头像</el-menu-item>
          <el-menu-item index="2-3"><i class="el-icon-edit"></i>重置密码</el-menu-item>
        </el-submenu>
        <el-menu-item index="3">
          <template>
            <el-button type="text" @click="logout"><i class="el-icon-edit"></i>退出</el-button>
          </template>
        </el-menu-item>
      </el-menu>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <div class="title">
          <img class="imgs" v-if="user.user_pic" :src="user.user_pic" alt="" />
          <img v-else class="imgs" src="../assets/logo.png" alt="" />
          欢迎你 <span> {{ user.nickname || user.username }}</span>
        </div>
        <el-menu
          active-text-color="rgb(95, 153, 203)"
          mode="vertical"
          text-color="#fff"
          background-color="rgb(35, 38, 46)"
        >
          <el-menu-item index="1"><i class="el-icon-edit"></i>首页</el-menu-item>
          <el-submenu index="2">
            <template slot="title"><i class="el-icon-edit"></i>文章管理</template>
            <el-menu-item index="2-1"><i class="el-icon-edit"></i>文章分类</el-menu-item>
            <el-menu-item index="2-2"><i class="el-icon-edit"></i>文章列表</el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title"><i class="el-icon-edit"></i>个人中心</template>
            <el-menu-item index="3-1"><i class="el-icon-edit"></i>基本资料</el-menu-item>
            <el-menu-item index="3-2"><i class="el-icon-edit"></i>修改头像</el-menu-item>
            <el-menu-item index="3-3"><i class="el-icon-edit"></i>重置密码</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>Main</el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'MyHome',
  created() {
    this.$store.dispatch('user/getUser')
  },
  computed: {
    ...mapState('user', ['user'])
  },
  methods: {
    logout() {
      this.$confirm('确定退出吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$store.commit('user/updateToken', '')
          this.$router.push('login')
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="less" scoped>
.el-container {
  width: 100%;
  height: 100%;
}
.el-header {
  display: flex;
  justify-content: space-between;
  height: 90px;
  background-color: rgb(35, 38, 46);
}
.el-aside {
  height: 100%;
  background-color: rgb(35, 38, 46);
}
.el-main {
  height: 100%;
  background-color: rgb(242, 242, 242);
}
.imgs {
  vertical-align: middle;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  object-fit: cover;
  background-color: #fff;
  margin-right: 20px;
}
.title {
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.el-button {
  color: #fff;
}
</style>
